<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">

<head>
    <meta name="viewport" content="width=device-width, initial-scale=1.0"/>

    <title th:text="${session.language['node-title']}"></title>
    <meta name="keywords" content=""/>
    <meta name="description" content=""/>

    <link href="../static/css/bootstrap.min.css?v=3.3.6" rel="stylesheet"/>
    <link href="../static/css/font-awesome.css?v=4.4.0" rel="stylesheet"/>
    <link href="../static/css/plugins/iCheck/custom.css" rel="stylesheet"/>
    <link href="../static/css/animate.css" rel="stylesheet"/>
    <link href="../static/css/style.css?v=4.1.0" rel="stylesheet"/>
</head>

<body class="gray-bg">
<div class="row wrapper border-bottom white-bg page-heading">
    <div class="col-sm-12">
        <h2 th:text="${session.language['node-title']}"></h2>
        <ol class="breadcrumb">
            <li>
                <span th:text="${session.language['manage-title']}"></span>
            </li>
            <li>
                <a href="/node-config">
                    <strong th:text="${session.language['node-title']}"></strong>
                </a>
            </li>
            <li>
                <a th:switch="${operation}">
                    <strong th:case="add" th:text="${session.language['add']}"></strong>
                    <strong th:case="edit" th:text="${session.language['edit']}"></strong>
                </a>
            </li>
        </ol>
    </div>
</div>
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5 th:text="${editTitle} + ' ' + ${session.language['node-title']}"></h5>
                </div>
                <div class="ibox-content">
                    <form class="form-horizontal">
                        <div class="form-group">
                            <label class="col-sm-2 control-label" th:text="${session.language['node-edit-id-title']}"></label>
                            <div class="col-md-8" th:if="${nodeConfig}==null" th:switch="${operation}">
                                <input type="text" name="id" class="form-control" th:case="add" th:attr="placeholder=${session.language['node-edit-id-tip']}"/>
                                <input type="text" name="id" class="form-control" disabled="" th:case="edit" th:attr="placeholder=${session.language['node-edit-id-tip']}"/>
                            </div>
                            <div class="col-md-8" th:if="${nodeConfig}!=null" th:switch="${operation}">
                                <input type="text" name="id" class="form-control" th:case="add" th:attr="placeholder=${session.language['node-edit-id-tip']}, value=${nodeConfig.id}"/>
                                <input type="text" name="id" class="form-control" disabled="" th:case="edit" th:attr="placeholder=${session.language['node-edit-id-tip']}, value=${nodeConfig.id}"/>
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label" th:text="${session.language['node-edit-name-title']}"></label>
                            <div class="col-md-8" th:if="${nodeConfig}==null">
                                <input type="text" name="name" class="form-control"
                                       th:attr="placeholder=${session.language['node-edit-name-tip']}"/>
                            </div>
                            <div class="col-md-8" th:if="${nodeConfig}!=null">
                                <input type="text" name="name" class="form-control"
                                       th:attr="placeholder=${session.language['node-edit-name-tip']}, value=${nodeConfig.name}"/>
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group" th:if="${operation}!='view'">
                            <div class="col-sm-4 col-sm-offset-2">
                                <button class="btn btn-info edit" type="button" th:text="${session.language['submit']}"></button>
                                <button class="btn btn-white" type="reset" th:text="${session.language['reset']}"></button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>

<!-- 全局js -->
<script src="../static/js/jquery.min.js?v=2.1.4"></script>
<script src="../static/js/bootstrap.min.js?v=3.3.6"></script>
<!-- 自定义js -->
<script src="../static/js/content.js?v=1.0.0"></script>
<!-- iCheck -->
<script src="../static/js/plugins/iCheck/icheck.min.js"></script>
<!-- Sweet alert -->
<link href="../static/css/plugins/sweetalert/sweetalert.css" rel="stylesheet"/>
<script src="../static/js/plugins/sweetalert/sweetalert.min.js"></script>
<script th:inline="javascript">
    $(document).ready(function () {
        $('.i-checks').iCheck({
            checkboxClass: 'icheckbox_square-green',
            radioClass: 'iradio_square-green',
        });

        $('.edit').click(function () {
            /*<![CDATA[*/
            var nodeIdTitle = [[${session.language['node-id']}]];
            var nodeNameTitle = [[${session.language['node-name']}]];

            var submitName = [[${session.language['submit']}]];
            var confirmTitle = [[${session.language['confirm-title']}]];
            var confirmSuccess = [[${session.language['confirm-success']}]];
            var confirmSuccessTip = [[${session.language['confirm-success-tip']}]];
            var confirmFailure = [[${session.language['confirm-failure']}]];
            var confirmFailureTip = [[${session.language['confirm-failure-tip']}]];
            /*]]>*/

            var nodeId = $("input[name='id']").val();
            var nodeName = $("input[name='name']").val();
            swal({
                title: confirmTitle,
                text:
                '<table border="0px" width="100%">' +
                '<tr><td align="right">' + nodeIdTitle + '</td><td>：</td><td align="left"><span style="color: #c7264e;background-color: #f9f2f4;">' + nodeId + '</span></td></tr>' +
                '<tr><td align="right">' + nodeNameTitle + '</td><td>：</td><td align="left"><span style="color: #c7264e;background-color: #f9f2f4;">' + nodeName + '</span></td></tr>' +
                '</table>',
                type: "info",
                html: true,
                showCancelButton: true,
                confirmButtonColor: "#23b7e5",
                confirmButtonText: submitName,
                closeOnConfirm: false
            }, function () {
                $.ajax({
                    url: "/submit-node-edit",
                    type: "POST",
                    data: {id: nodeId, name: nodeName},
                    dataType: "json",
                    success: function (data) {
                        if (data) {
                            swal(confirmSuccess, confirmSuccessTip, "success");
                        } else {
                            swal(confirmFailure, confirmFailureTip, "error");
                        }
                    },
                    error: function (e) {
                        var m = e.responseJSON;
                        swal(confirmFailure, "[" + m.status + " - " + m.error + "] " + m.message, "error");
                    }
                });
            });
        });
    });
</script>
</body>
</html>